
<?php

jimport('joomla.application.component.controller');

class folderController extends JController {
    public function __construct(){
        parent::__construct();
        $this->model = new folderModelFolder();
    }
    
    public function getFolderList(){
        $model = $this->getModel();
        
        $user_name = jfactory::getUser()->username;
        
        $result = $model->getFolderList($user_name);
        
        echo "<option value='0'> 個人用フォルダ</option>";
        if(!empty($result)){
            foreach($model->getFolderList($user_name) as $folder){
                echo "<option value='$folder->FOME_CODE'>$folder->FOME_NAME</option>";
            }
        }           
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    public function createFolder(){
        $model = $this->getModel();
        
        $user_name = jfactory::getUser()->username;
        
        $name = JRequest::getVar('name');
        $parent = JRequest::getVar('parent');
        
        echo json_encode($model->createFolder($name, $parent, $user_name));
                
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    public function deleteFolder(){
        $model = $this->getModel();
        
        $user_name = jfactory::getUser()->username;
        
        $code = JRequest::getVar('code');
        
        echo json_encode($model->deleteFolder($user_name, $code));
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    public function editFolder(){
        $model = $this->getModel();
        
        $user_name = jfactory::getUser()->username;
        
        $name = JRequest::getVar('name');
        $parent = JRequest::getVar('parent');
        $code = JRequest::getVar('code');
        
        echo json_encode($model->editFolder($name, $parent, $code, $user_name));
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    public function clearFolder(){
        $model = $this->getModel();
        
        $user_name = jfactory::getUser()->username;
        
        $code = JRequest::getVar('code');
        
        echo json_encode($model->clearFolder($user_name, $code));
        
        $app = &JFactory::getApplication();
        $app->close();
    }
}
